package com.jia.lidao.others.adapter;

import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jia.lidao.R;
import com.jia.lidao.others.enity.Address;

public class AddressAdapter extends QuickAdapter<Address.AddressesBean.DataBean> {
    private  OnDefaultClickListener onDefaultClickListener;
    private OnEditListener onEditListener;
    private  OnDeletListener onDeletListener;
    private int type;

    @Override
    public int getLayoutID(int viewType) {
        return R.layout.address_adapter_time;
    }

    public AddressAdapter(int type){
        this.type=type;
    }

    @Override
    public void convert(VH holder,final Address.AddressesBean.DataBean itemData,final int position) {
        TextView tvName = holder.getView(R.id.tv_name);
        tvName.setText(itemData.getConsignee());

        RelativeLayout addressrl=holder.getView(R.id.address_rl);

        TextView tvPhone = holder.getView(R.id.tv_phone);
        tvPhone.setText(itemData.getPhone());
        TextView tvAddress = holder.getView(R.id.tv_address);
        String address = itemData.getProvince_name() +itemData.getCity_name() +itemData.getCounty_name() +itemData.getStreet();
        tvAddress.setText(address);
        //默认地址：0否 1是 ,
        TextView ckDefault = holder.getView(R.id.ck_default);
        if(itemData.getIs_default() == 0){
            ckDefault.setSelected(false);
            ckDefault.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if(null != onDefaultClickListener){
                        onDefaultClickListener.listener(itemData,position,true);
                    }
                }
            });
        }else {
            ckDefault.setSelected(true);
        }


        TextView tvEdit = holder.getView(R.id.tv_edit);
        tvEdit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(null != onEditListener){
                    onEditListener.listener(itemData,position);
                }
            }
        });
        if(type!=0){
            if(null!=onEditListener){
                addressrl.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        onEditListener.listener(itemData,position);
                    }
                });

            }
        }
        TextView tvDelete = holder.getView(R.id.tv_delete);
        tvDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(null != onDeletListener){
                    onDeletListener.listener(itemData,position);
                }
            }
        });
    }

    public interface OnDefaultClickListener{
        void listener(Address.AddressesBean.DataBean itemData, int position,Boolean isDefault);
    }

    public void setOnDefaultClickListener(OnDefaultClickListener onDefaultClickListener) {
        this.onDefaultClickListener = onDefaultClickListener;
    }

    public interface OnEditListener{
        void listener(final Address.AddressesBean.DataBean itemData,final int position);
    }

    public void setOnEditListener(OnEditListener onEditListener) {
        this.onEditListener = onEditListener;
    }

    public interface OnDeletListener{
        void listener(final Address.AddressesBean.DataBean itemData, final int position);
    }

    public void setOnDeletListener(OnDeletListener onDeletListener) {
        this.onDeletListener = onDeletListener;
    }
}